﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<title>PHPMall {$goodsInfo.goods_name}</title>
	<meta name="Copyright" content="{$confRes.miaoshu}"/>
	<meta name="Keywords" content="{$confRes.sitename}"/>
	<meta name="Description" content="{$confRes.miaoshu}"/>
	<link rel="stylesheet" type="text/css" href="/static/index/css/pc-jifen-store.8e8389f4.css">
	<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
	<script src="/static/layer/jquery.min.js"></script>
	<script src="/static/layer/layer.js"></script>
</head>
<body>

<div id="header" class="header">
	<!--个人状态-->
	{include file="public/topmenu"}
	<!--个人状态end-->
	<!--导航栏-->
	{include file="public/topnav"}
	<!--导航栏end-->

</div>


<div class="content">
	<ol class="breadcrumb">
		<li><a href="/">商品分类</a><span class="diagonal">/</span></li>
		<li><a href="javascript:void(0);" class="active">{$goodsInfo.goods_name}</a></li>
	</ol>
	<div class="product-intro cf">
		<div class="product-preview">
			<div class="product-img">
				<img id="productMainPic" src="/static/uploads/{$goodsInfo.og_thumb}">
			</div>
			<div class="thumbnails">
				<ul class="thumbnail-list cf">
					{volist name="$goodsInfo.images" id="images"}
					<li class="thumbnail-item active">
						<a href="javascript:void(0);"><img src="/{$images.img_path}" alt="{$goodsInfo.goods_name}"></a>
					</li>
					{/volist}
				</ul>
			</div>
		</div>
		<div class="product-info">
			<div class="product-name">
				<h2 class="title">{$goodsInfo.goods_name}</h2>
				<p class="txt">{$goodsInfo.goods_name}</p>
			</div>
			<div class="product-price">
				<p><span class="current-price">￥<span id="salePrice" class="num">{$goodsInfo.shop_price}</span></span>
					<del class="old-price">原价￥<span id="price" class="num">{$goodsInfo.markte_price}</span></del>
				</p>
			</div>

				<div class="product-custom">
					<h3>商品属性</h3>
					<ul class="">
						{volist name="$goodsInfo.product" id="product"}
						<li class="custom-item"  >{$product.name}：{$product.detail}</li>
						{/volist}
					</ul>
				</div>

				<div class="product-quantity"  >
					<h3>数量</h3>
					<div id="quantityInput" class="quantity-input">
						<button type="button"  onclick='changeQty(0,"{$goodsInfo.id}");' class="reduce">
							<i class="icon-reduce"   ></i>
						</button>
						<form method="post" action="{:url('index/goods/immediately')}">
						<input type="text" onkeyup='change_quantity("{$goodsInfo.id}",this);'  name="quantity"  id="quantity" class="quantity-input-tx" value="1">
						<input type="hidden"   name="g_id"   value="{$goodsInfo.id}">
						<button type="button" onclick='changeQty(1,"{$goodsInfo.id}");'  class="add">
							<i class="icon-add" ></i>
						</button>
					</div>
						<span id="quantityTips" class="stock-txt">
							{if $goodsInfo.stock != 0}
								( 还剩{$goodsInfo.stock}件 )
							{else}
								( 库存不足 )
							{/if}
						</span>
				</div>

				<div class="product-buy">
					{if $goodsInfo.stock != 0}
					{if $Think.session.user}
					<a href="javascript:void(0);" id="addToCartButton" onclick="addCatr('{$goodsInfo.id}')" class="js_buy-button btn btn-big btn-green cart">加入购物车</a>
					<input type="submit" class="js_buy-button btn btn-big btn-red buy" value="立即购买">
					<form>
					<i class="fly-item" id="fly-item"></i>
					{else}
					<a href="{:url('user/login/login')}" id="" class="js_buy-button btn btn-big btn-green cart">加入购物车</a>
					<a href="{:url('user/login/login')}"  id="buyNowButton" class="js_buy-button btn btn-big btn-red buy">立即购买</a>
					<i class="fly-item" id="fly-item"></i>
					{/if}
					{else}
					<a href="javascript:void(0);" class="js_oversold-button btn btn-big btn-disabled soldout" >已售罄</a>
					{/if}
				</div>
		</div>
	</div>
	<div id="productDetail" class="product-detail">
		<div class="detail-subnav">
			<ul class="cf">
				<li class="subnav-item active">
					<a href="javascript:void(0);">商品详情</a>
					<i class="horizontal-line"></i>
				</li>
				<li class="subnav-item">
					<a href="javascript:void(0);">商品评论</a>
					<i class="horizontal-line"></i>
				</li>
			</ul>
		</div>
		<div class="detail-content">
			<div class="content-item contact_item active">
					<?php echo $goodsInfo['goods_des'];?>
			</div>
			<div class="content-item contact_item">


			</div>
		</div>
	</div>
</div>

<script>
	

    // 加入购物车
    function addCatr(goods_id) {
        var quantity = $("#quantity").val();  // 商品数量
        $.ajax({
            url:"{:url('user/Cart/addCart')}",
            type:"POST",
            dataType:"json",
            data:{
                goods_id:goods_id,
                quantity:quantity
            },
            success:function (res) {
                if(res.code === -1){
                    return layer.alert(res.msg)
                }else if(res.code === 1) {
                    layer.alert(res.msg,function () {
                        window.location.reload();  //刷新父级页面
                    })
                }
            }
        });
    }


    // 更改数量
    function changeQty(num,goods_id) {
        // 获取现有的数量
        var quantity = $("#quantity").val();
        if (num === 0){
            if(quantity == 1 || quantity < 1){
                layer.alert('最小起订量是1 件');
                $("#quantity").val(1);

                return ;
            }else {
                $("#quantity").val(quantity-1);
            }
        }else {
            // 通过ajax请求 查询商品库存。
            $.ajax({
                url:"{:url('index/Goods/getGoodsStock')}",
                type:"POST",
                dataType:"json",
                data:{
                    goods_id:goods_id
                },
                success:function (res) {
                    if(quantity >= res){
                        layer.alert('该商品数量不足，剩余 '+ res+' 件')
                        $("#quantity").val(res);
                    }else {
                        $("#quantity").val(parseInt(quantity) + 1);
                    }
                }
            });

        }
    }

    function change_quantity(goods_id,obj) {
        var quantity = $(obj).val();
        if(quantity<1){
            $("#quantity").val(1);
        }
        if(isNaN(quantity)){
            $("#quantity").val(1);
        }
        // 通过ajax请求 查询商品库存。
        $.ajax({
            url:"{:url('index/Goods/getGoodsStock')}",
            type:"POST",
            dataType:"json",
            data:{
                goods_id:goods_id
            },
            success:function (res) {
                if(quantity > res){
                    layer.alert('该商品数量不足，剩余 '+ res+' 件')
                    $("#quantity").val(res);
                }
            }
        });
    }


</script>
<!--尾部-->
{include file="public/footer"}
<!--尾部end-->
<script type="text/javascript" src="/static/index/js/c22559310a7b450cbe60c70169dd1d6f.js" charset="UTF-8"></script>

<script>var gConfigs = {
    js: {"cgiHost":"//jifen.qq.com"},
	productId: 4380, userJifen: 945,
	specLength: 1 };
</script>

<script type="text/javascript" src="/static/index/js/midaslogdata.3586e7e2.js"></script>
<script type="text/javascript" src="/static/index/js/item.5532932b.js"></script>
<script>logData.report('pcjifen.item.pv', {productid: "4380"})</script>
</body>
</html>
